package vip.mengqin.diandezhun.ui.activity;

import android.view.View;
import android.widget.ImageView;

import com.android.baselibrary.dialog.Comm_DialogFragment;
import com.android.baselibrary.util.GlideUtil;
import com.android.baselibrary.view.Comm_HeadView;
import com.android.baselibrary.view.Comm_TitleView;
import com.android.baselibrary.view.MultiStateView;

import butterknife.BindView;
import butterknife.OnClick;
import vip.mengqin.diandezhun.R;
import vip.mengqin.diandezhun.bean.UserInfo;
import vip.mengqin.diandezhun.manager.UserManager;

public class UserCenterActivity extends BaseActivity{

    @BindView(R.id.multiplestatusView)
    MultiStateView multiplestatusView;
    @BindView(R.id.comm_title)
    Comm_HeadView comm_title;
    @BindView(R.id.iv_head)
    ImageView iv_head;
    @BindView(R.id.ctv_username)
    Comm_TitleView ctv_username;
    @BindView(R.id.ctv_phone)
    Comm_TitleView ctv_phone;
    @BindView(R.id.ctv_sex)
    Comm_TitleView ctv_sex;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_usercenter;
    }

    @Override
    protected void initView() {
        comm_title.setTitle("个人中心");
    }

    @Override
    protected void initData() {
        showUserInfo();
    }

    //刷新用户信息
    private void showUserInfo() {
        if (UserManager.isLogin(mContext)) {
            UserInfo userInfo = UserManager.getUserInfo(mContext);
            if (userInfo != null) {
                GlideUtil.displayImage(mContext, userInfo.avatar, iv_head, R.drawable.ico_default_img_fang);
                ctv_username.setContent(userInfo.nickname);
                ctv_phone.setContent(userInfo.mobile);
            }
        } else {
            //未登录

        }
    }

    private void getData()
    {
//        API_Manager.sendcode(mContext, "", new OkHttpCallBack<BaseResponce<String>>() {
//            @Override
//            public void onSuccess(BaseResponce<String> baseResponce) {
//                CommToast.showToast(mContext, "发送成功");
//            }
//
//            @Override
//            public void onFailure(BaseResponce<String> baseResponce) {
//                CommLoading.dismissLoading();
//                CommToast.showToast(mContext, baseResponce.message);
//            }
//        });
    }

    @OnClick({R.id.tv_logout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_logout:     //退出登录
                Comm_DialogFragment.showCommDialog(getSupportFragmentManager(), "", "确定退出登录吗", "确定", "取消", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        UserManager.logout(mContext);
                        finish();
                    }
                }, null);
                break;
        }
    }

}
